package com.CityHunter.Request;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;

import android.util.Log;

import com.CityHunter.Common.Http;

public class RegisterRequest {

	private String registerPage;
	
	public RegisterRequest(String registerPage){
		this.registerPage = registerPage;
	}
	
	public int sendRequest(String email,String password,String name){
		
		int result = 0;
		
		// Declare NameValuePair to store the data
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("email", email));
		params.add(new BasicNameValuePair("password", password));
		params.add(new BasicNameValuePair("name", name));
		
		// Send Register Request
		Http http = new Http();
		Log.d("Sttp_Debug", "Sending Request : " + registerPage);
		JSONArray jsonResponse = http.sendRequest(registerPage, params);
		try {
			result = Integer.parseInt(jsonResponse.getJSONObject(0)
					.getString("result"));
			Log.d("Sttp_Debug", "Server Response : Result = " + result);
		} catch (Exception e) {
			Log.e("Sttp_Error", e.getMessage().toString());
		}
		
		return result;
		
	}
	
}
